package com.contest;

public class Solutioin1662 {
    public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
        int m = 0;
        int n = 0;
        int i = 0;
        int j = 0;
        while (m < word1.length && n < word2.length) {
            while (i < word1[m].length() && j < word2[n].length()) {
                if (word1[m].charAt(i) != word2[n].charAt(j)) return false;
                else {
                    i++;
                    j++;
                }
            }
            if (i == word1[m].length()) {
                m++;
                i = 0;
            }
            if (j == word2[n].length()) {
                n++;
                j = 0;
            }
        }
        return m == word1.length && n == word2.length;
    }
}
